package com.dg11185.nearshop.view.adapter;

import java.util.List;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.nearshop.R;
import com.dg11185.nearshop.app.ConvertUnit;
import com.dg11185.nearshop.net.entity.CommentReply;

public class ReplyCommentAdapter extends BaseAdapter {

    private LayoutInflater inflater = null;

    private List<CommentReply> replys = null;

    /**
     * 构造函数
     * 
     * @param context
     * @param shops
     *            需要保证数据被初始化，如果使用set函数初始化BaseAdapter可能会报空指针；
     */
    public ReplyCommentAdapter(Context context, List<CommentReply> replys) {
        inflater = LayoutInflater.from(context);
        this.replys = replys;
    }

    public void setComments(List<CommentReply> replys) {
        this.replys = replys;
    }

    @Override
    public int getCount() {
        return replys.size();
    }

    @Override
    public Object getItem(int position) {
        return replys.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        CommentReply unit = replys.get(position);
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.shop_comment_reply_item, parent, false);
            holder.name = (TextView) convertView.findViewById(R.id.reply_item_name);
            holder.content = (TextView) convertView.findViewById(R.id.reply_item_content);
            holder.time = (TextView) convertView.findViewById(R.id.reply_item_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String text = "<font color=#EC0C65> "+ unit.userName + " :@ "+ unit.toReplyUserName + " </font><font color=#000000>" + unit.content
                + "</font>";

//        holder.name.setText(unit.userName);
        holder.content.setText(Html.fromHtml(text));
        holder.time.setText(ConvertUnit.dateConvert(unit.createTime));
        return convertView;
    }

    private class ViewHolder {
        private TextView name;

        private TextView content;

        private TextView time;
    }
}
